package memory;

import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.Serializable;

@SuppressWarnings("serial")



//NOTE: Only even m x n entries for obvious reasons!
public class CardPanel extends JPanel implements Serializable {

	private int nrCards = Options.getRows() * Options.getCols();
	private Card[] cardArray;
		
	public CardPanel() {
		cardArray = Tools.createCards();
		createPanel();
	}
	
	//For net games
	public CardPanel(Card[] cards) {
		cardArray = cards;
		createPanel();
	}
	
	//"Create" new CardPanel with m x n cards (rows x columns)
	private void createPanel() {
		
		//Change the width and of the cards here
		Dimension cardDimension = new Dimension(100,100);
		
		//Create grid and add cards to it.
		this.setLayout(new GridLayout(Options.getRows(), Options.getCols()));
			
		for( int i = 0 ; i < nrCards ; i++ ) {
			cardArray[i].setStatus(Card.State.DOLT);
			cardArray[i].setPreferredSize( cardDimension );
			this.add(cardArray[i]);
		}
		
	}
	
	public int getNrOfCards() {
		return nrCards;
	}

	public Card getCard(int nr) {
		return cardArray[ nr ];
	}
	
}